/**
 * Copyright 2008 Frank van Lingen Licensed under the Apache License, Version
 * 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package superpodder;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;

import superpodder.gui.MainView;

// use an obscure port

public class SuperPodder {

    /**
     * Main class of the rssfeed manager.
     * 
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        // Get the System Classloader
        ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();

        // Get the URLs
        URL[] urls = ((URLClassLoader) sysClassLoader).getURLs();

        for (int i = 0; i < urls.length; i++) {
            System.out.println("URL file names " + urls[i].getFile());
        }
        

        final String path = System.getProperty("user.dir");
        try {
            // use a proper lock file name.
            final File file = new File(path + "\\SuperPodder.lock");
            // if the file doesn't exist you know that there isn't another
            // instance of your application running.
            if (file.exists()) {
                System.out.println("Lock exists!");
                if (file.delete()) {
                    // test if the app can delete the lock file.
                    System.out.println("Lock deleted!");
                    // no other instance was locking the file
                } else {
                    System.out
                            .println("An instance of this application is already running.");
                    // the deletion wasn't possible because another instance of
                    // your application was locking the file.
                    System.exit(0);
                }
            }
        } catch (final Exception nop) {
        }

        FileWriter lock;
        try {
            lock = new FileWriter(path + "\\SuperPodder.lock"); // the same lock
            // file name.
        } catch (final IOException nop) {
        }

        final MainView view = new MainView();
        view.showCentered();

        // FileDialog fileDialog = new FileDialog(display);

    }

}
